package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.JobPlanBillAccount;
import com.ruoyi.system.mapper.JobPlanBillAccountMapper;
import com.ruoyi.system.service.JobPlanBillAccountService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作业计划-台账(JobPlanBillAccount)表服务实现类
 *
 * @author makejava
 * @since 2022-11-23 09:20:09
 */
@Service("jobPlanBillAccountService")
public class JobPlanBillAccountServiceImpl implements JobPlanBillAccountService {
    @Resource
    private JobPlanBillAccountMapper jobPlanBillAccountDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public JobPlanBillAccount queryById(Integer id) {
        return this.jobPlanBillAccountDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param jobPlanBillAccount 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<JobPlanBillAccount> queryByPage(JobPlanBillAccount jobPlanBillAccount, PageRequest pageRequest) {
        long total = this.jobPlanBillAccountDao.count(jobPlanBillAccount);
        return new PageImpl<>(this.jobPlanBillAccountDao.queryAllByLimit(jobPlanBillAccount, pageRequest), pageRequest, total);
    }

    @Override
    public List<JobPlanBillAccount> queryAll(JobPlanBillAccount jobPlanBillAccount) {
        return jobPlanBillAccountDao.queryAll(jobPlanBillAccount);
    }

    /**
     * 新增数据
     *
     * @param jobPlanBillAccount 实例对象
     * @return 实例对象
     */
    @Override
    public JobPlanBillAccount insert(JobPlanBillAccount jobPlanBillAccount) {
        this.jobPlanBillAccountDao.insert(jobPlanBillAccount);
        return jobPlanBillAccount;
    }

    /**
     * 修改数据
     *
     * @param jobPlanBillAccount 实例对象
     * @return 实例对象
     */
    @Override
    public JobPlanBillAccount update(JobPlanBillAccount jobPlanBillAccount) {
        this.jobPlanBillAccountDao.update(jobPlanBillAccount);
        return this.queryById(jobPlanBillAccount.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.jobPlanBillAccountDao.deleteById(id) > 0;
    }
}
